﻿using CRMBiz.CalculateInterest;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRMWeb.Pages.Test
{
    public partial class TestSimpleIntrestCalculator : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Label2.Visible = true;
            txtTerm.Visible = true;
            Label9.Visible = false;
            txtRepayment.Visible = false;

            decimal loanAmount = Convert.ToDecimal(txtLoanAmount.Text);
            int term = Convert.ToInt16(txtTerm.Text);
            int daysBetweenRepayments = Convert.ToInt16(txtDaysBetween.Text);
            DateTime settlementDate = Convert.ToDateTime(txtFirstDate.Text);
            DateTime firstPaymentDate = Convert.ToDateTime(txtFirstPaymentDate.Text);
            decimal annumInterestRate = Convert.ToDecimal(txtInterestRatePA.Text);

            DataTable dtSchedule = new DataTable();
            dtSchedule = SimpleInterest.SimpleInterestPaymentScheduleByTerm(term, loanAmount, daysBetweenRepayments, settlementDate, firstPaymentDate, annumInterestRate);

            dvSchedule.DataSource = dtSchedule;
            dvSchedule.DataBind();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Label2.Visible = false;
            txtTerm.Visible = false;
            Label9.Visible = true;
            txtRepayment.Visible = true;

            decimal loanAmount = Convert.ToDecimal(txtLoanAmount.Text);// 5000;
            decimal repaymentAmount = Convert.ToDecimal(txtRepayment.Text);
            int daysBetweenRepayments = Convert.ToInt16(txtDaysBetween.Text);
            DateTime settlementDate = Convert.ToDateTime(txtFirstDate.Text);
            DateTime firstPaymentDate = Convert.ToDateTime(txtFirstPaymentDate.Text);
            decimal annumInterestRate = Convert.ToDecimal(txtInterestRatePA.Text);

            DataTable dtSchedule = new DataTable();
            dtSchedule = SimpleInterest.SimpleInterestPaymentScheduleByRepayment(repaymentAmount, loanAmount, daysBetweenRepayments, settlementDate, firstPaymentDate, annumInterestRate);

            dvSchedule.DataSource = dtSchedule;
            dvSchedule.DataBind();
        }
    }
}